<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="补贴单">
              <el-input v-model="form.applySn" placeholder="请输入补贴单号" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励人姓名">
              <el-input v-model="form.refereeRealname" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励人电话">
              <el-input v-model="form.refereeUsername" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="级别">
              <el-select v-model="form.roleId" placeholder="请选择">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励类型">
              <el-select v-model="form.awardType" placeholder="请选择">
                <el-option
                  v-for="item in awardTypeList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励时间" width="236">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                :default-time="['00:00:00', '23:59:59']"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="推荐消费类型">
              <el-select v-model="form.moneyBaseType" @clear="abc('moneyBaseType')" clearable>
                <el-option label="全部" :value="null" />
                <el-option label="现金消费" :value="1" />
                <el-option label="积分消费" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
              <el-button
                plain
                type="primary"
                class="el-icon-download"
                @click="excelEvent"
                v-if="permissionJson.indexOf('AdminUserRewardTransProvider.rewardExport') !=-1"
              >导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="applySn" label="补贴单号" />
        <el-table-column prop="realname" label="报单姓名" />
        <el-table-column prop="username" label="报单手机号">
          <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="奖励金额" />
        <el-table-column prop="refereeUsername" label="奖励手机号">
          <template slot-scope="scope">
            <div>{{scope.row.refereeUsername | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="moneyBaseTypeValue" align="center" label="推荐消费类型" />
        <el-table-column prop="goldAwardFreezeValue" align="center" label="金币奖励是否冻结" />
        <el-table-column prop="refereeRealname" label="奖励姓名" />
        <el-table-column prop="refereeRoleName" label="奖励推荐人级别" />
        <el-table-column prop="awardType" label="奖励详情">
          <template slot-scope="scope">{{scope.row.awardType}}</template>
        </el-table-column>
        <el-table-column prop="transTime" label="奖励时间" />
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { subsidyChildrenFOIndexList, rewardExport } from "@/api/financialOther";
// import { exportfile } from "@/api/commjs/exprot";
import { exportfile } from "@/api/exporfile";
export default {
  name: "SubsidyChildrenFOIndex",
  filters: {},
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      tableLoading: true,
      dates: [],
      form: {
        applySn: "",
        realname: "",
        username: "",
        roleId: null,
        awardType: null,
        startTransTime: null,
        endTransTime: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100, 500, 1000],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      },
      roleOptions: [
        { id: null, name: "全部" },
        { id: 2, name: "美学设计师" },
        { id: 3, name: "高级美学设计师" },
        { id: 7, name: "分公司合伙人" },
        { id: 8, name: "高级分公司合伙人" }
      ],
      awardTypeList: [
        { id: null, name: "全部" },
        { id: 1, name: "一级服务商奖励" },
        { id: 2, name: "二级服务商奖励" },
        { id: 3, name: "团队奖励" },
        { id: 4, name: "区域省奖励(老) " },
        { id: 5, name: "区域市奖励(老)" },
        { id: 6, name: "特殊奖励" },
        { id: 7, name: "省奖励（新）" },
        { id: 8, name: "大区域奖励" },
        { id: 9, name: "业绩二单奖励" },
        { id: 10, name: "团队二单奖励" },
        { id: 11, name: "业绩奖励（系统加减）" },
        { id: 12, name: "团队奖励（系统加减）" },
        { id: 13, name: "试用业绩奖励" },
        { id: 14, name: "试用团队奖励" },
        { id: 15, name: "试用大区域奖励" },
        { id: 16, name: "会员分销奖励" },
        { id: 17, name: "序列码奖励" }
      ]
    };
  },
  mounted() {
    this.getList(this.listForm);
  },
  methods: {
    //清空
    abc(val) {
      if (!this.form[val]) this.form[val] = null;
      console.log(val, this.form[val]);
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      subsidyChildrenFOIndexList(datas)
        .then(res => {
          // console.log(res)
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
            if (this.tableData.length > 0) {
              this.tableData.forEach(item => {
                this.awardTypeList.forEach(list => {
                  if (item.awardType == list.id) item.awardType = list.name;
                });
                this.roleOptions.forEach(type => {
                  if (item.refereeRoleName == type.id)
                    item.refereeRoleName = type.name;
                });
              });
            }
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if (this.dates != null) {
        if (this.dates.length) {
          this.form.startTransTime = this.dates[0];
          this.form.endTransTime = this.dates[1];
        }
      } else {
        this.form.startTransTime = null;
        this.form.endTransTime = null;
      }
      this.getList(this.form);
      // console.log(JSON.stringify(this.form))
    },
    //导出
    excelEvent() {
      // this.form.pageSize = 1000;
      // exportfile("/com.mmk.reservation.api.AdminUserRewardTransProvider/1.0.0/rewardExport.html", this.form, 1);
      rewardExport(this.form).then(res => {
        exportfile(res);
      });
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
